package com.aos.erp.schools.service.coach.impl;

import com.aos.erp.schools.enums.student.IsDel;
import com.aos.erp.schools.mapper.coach.CoachCarMapper;
import com.aos.erp.schools.model.coach.CoachCar;
import com.aos.erp.schools.model.coach.Dto.CoachCarDto;
import com.aos.erp.schools.service.coach.CoachCarService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: erp
 * @description:
 * @author: tanzhiyu
 * @create: 2018-11-12 14:08
 **/
@Service
public class CoachCarServiceImpl extends ServiceImpl<CoachCarMapper, CoachCar> implements CoachCarService {
    @Resource
    private CoachCarMapper coachCarMapper;

    @Override
    public void addBean(CoachCar coachCar) throws Exception {
        coachCar.setCreated(new Date());
        coachCar.setIsDel(Integer.valueOf(IsDel.normal.getValue().toString()));
        coachCarMapper.insert(coachCar);
    }

    @Override
    public int isDel(String id) throws Exception {
        CoachCar coachCar = new CoachCar();
        coachCar.setId(Long.valueOf(id));
        coachCar.setIsDel(Integer.valueOf(IsDel.del.getValue().toString()));
        int i = baseMapper.updateObject(coachCar);
        return i;
    }
    @Override
    public CoachCarDto getInfo(String id){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        List<CoachCarDto> list = coachCarMapper.findByParams(map);
        if(list!=null && list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public IPage<CoachCarDto> queryByPage(Integer pageIndex, Integer pageSize, String carId, String coachId, String coachName) {
        Page<CoachCarDto> pageBean = new Page<CoachCarDto>(pageIndex, pageSize);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("carId", carId);
        map.put("coachId", coachId);
        map.put("coachName", coachName);
        map.put("isDel", IsDel.normal.getValue().toString());
        map.put("pageBean", pageBean);
        List<CoachCarDto> list = coachCarMapper.findByParams(map);
        IPage<CoachCarDto> page = pageBean;
        page.setRecords(list);
        return page;
    }

    /**
     * 分页查询
     *
     * @param pageIndex 当前页码
     * @param pageSize  每页显示条数
     * @param carId     车辆id
     * @param coachId   教练id
     * @param coachName 教练名称
     * @param depCode    部门组织code
     * @return
     */
    public IPage<CoachCarDto> selectByParams(Integer pageIndex, Integer pageSize, String carId, String coachId, String coachName,String depCode){
        Page<CoachCarDto> pageBean = new Page<CoachCarDto>(pageIndex, pageSize);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("carId", carId);
        map.put("coachId", coachId);
        map.put("depCode", depCode);
        map.put("coachName", coachName);
        map.put("isDel", IsDel.normal.getValue().toString());
        map.put("pageBean", pageBean);
        List<CoachCarDto> list = coachCarMapper.selectByParams(map);
        IPage<CoachCarDto> page = pageBean;
        page.setRecords(list);
        return page;
    }

    @Override
    public int updateObject(CoachCar coachCar) throws Exception {
        return coachCarMapper.updateObject(coachCar);
    }

    @Override
    public List<CoachCarDto> findByParams(Map<String, Object> map) throws Exception {
        return null;
    }


}
